home *** CD-ROM | disk | FTP | other *** search
- /*
- **
- ** nucall.c
- **
- */
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/mman.h>
- #include <time.h>
- #include <fcntl.h>
- #include <string.h>
- #include <signal.h>
- #include <termio.h>
-
-
- int done();
- int quit();
-
- int mon_handle;
- long start;
- char name[512];
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- struct stat st;
- char call[8];
- char *line;
- char *p;
- long idsize;
- char c[2];
- char buf[512];
- char look[256];
- char pbuf[2048];
- int lookt;
- int counter;
- int found;
- int pause = 0;
- time_t now;
- FILE *cp;
- FILE *fp;
- FILE *wfp;
-
- time(&start);
- setmodes();
- if ((cp=fopen("93061.cbk","r")) == NULL)
- {
- printf("Error opening callbook.db\n\r");
- quit();
- }
-
- signal(SIGALRM,(void *)done);
- alarm(900);
- signal(SIGHUP,(void *)quit);
- signal(SIGINT,(void *)quit);
- signal(SIGQUIT,(void *)quit);
-
- monitor();
- mprintf("\n\rWelcome to the AA7BQ Callsign Server\n\r");
-
- if ((wfp=fopen("welcome.callbook","r")) != NULL)
- {
- while (!feof(wfp))
- { fgets(buf,sizeof(buf),wfp);
- mprintf(buf);
- }
- fclose(wfp);
- }
-
- memset(name,0,sizeof(name));
- while(!strlen(name))
- {
- mprintf("\n\rPlease enter your name -> ");
- strin(name,0);
- counter++;
- if (counter == 5)
- quit();
- }
- mprintf("\n\r\n\rHello %s, you have 15 minutes to use the database.\n\r",
- name);
-
- time(&now);
- if (fp=fopen("/tmp/bbs.user","w"))
- {
- strftime(buf,128,"%T",localtime(&now));
- fprintf(fp,"%s (Callbook) on at %s",name,buf);
- fclose(fp);
- }
-
- mprintf("\n\rThe data presented on this system was copied\n\r");
- mprintf("from the FCC records on March 3, 1993.\n\r\n\r");
-
- mprintf("Do you want the listing to pause after each 3 names? [Y/n] ==> ");
- strin(buf,0);
- if (toupper(buf[0]) != 'N')
- pause++;
-
- mprintf("\n\r");
- c[1] = '\0';
- while (&counter)
- {
- memset(look,0,sizeof(look));
- memset(buf,0,sizeof(buf));
- mprintf("\n\r");
-
- mprintf("Enter C for Call search, N for Name search or Q to Quit:\n\r\n\r");
- mprintf("Please choose C, N or Q ==> ");
-
- c[0] = toupper((char) getchar());
- mprintf("%s\n\r",c);
-
- if (c[0] == 'Q')
- quit();
-
- if (c[0] == '\n' || c[0] == '\r')
- c[0] = 'C';
-
- if (c[0] != 'C' && c[0] != 'N')
- {
- mprintf("\n\rInvalid choice! The options are C, N or Q.\n\r");
- continue;
- }
- if (c[0] == 'N')
- {
- alphalook(cp,pause);
- continue;
- }
- mprintf("\n\rEnter a Callsign or Q to Quit -> ");
- strin(buf,1);
- mprintf("\n\r");
- sscanf(buf,"%s",look);
-
- if (!strlen(look))
- continue;
-
- if (look[0] == 'Q')
- continue;
-
- if ((int)strlen(look) > 7)
- {
- mprintf("Improper callsign format -> '%s' Please try again\n\r",look);
- continue;
- }
-
- memset(call,0,sizeof(call));
- strncpy(call,look,7);
-
- found = clook(cp,call,buf);
-
- if (found)
- {
- pcall(buf,mprintf);
- }
- else
- mprintf("\n\r%s not found in callbook database.\n\r\n\r",call);
- }
- done();
- }
-
- alphalook(cp,pause)
- FILE *cp;
- int pause;
- {
- char sav[32];
- char buf[32];
- int recs;
-
- mprintf("\n\rEnter a name or partial name, in the form of: LAST FIRST MI\n\r");
- mprintf("to search for. Example: ==> Lloyd Fred L\n\r\n\r");
- mprintf("Enter Name: ==> ");
- strin(buf,0);
-
- if (!strlen(buf))
- return;
-
- strcpy(sav,buf);
- mprintf("\r\n\r\n");
-
- recs = namefind(cp,buf,pause,mprintf);
-
- if (recs)
- mprintf("%d record(s) matched pattern '%s'.\n\r\n\r",
- recs, sav);
- else
- mprintf("Pattern '%s' Not Found\n\r\n\r",sav);
- }
-
- done()
- {
- mprintf("\n\r\n\rYour usage limit has been reached.");
- quit();
- }
-
- quit()
- {
- FILE *fp;
- char str[256];
- char when[32];
- long now;
-
- mprintf("\n\r\n\rThanks %s, for calling the AA7BQ Callsign Server.\n\r", name);
- mprintf("Be sure and log in as 'BBS' sometime and check out the additional\n\r");
- mprintf("features available on this system. 73's -fred AA7BQ\n\r");
- time(&now);
-
- strftime(when,32,"%D %T",localtime(&now));
- sprintf(str,"%s %s %d:%02d mins\n",when,name,
- (now-start)/60,(now-start)%60);
-
- if (fp = fopen("call.log","a+"))
- fputs(str,fp);
- sleep(3);
- restoremodes();
- exit(0);
- }
-
- strin(s,q)
- char *s;
- int q;
- {
- char c;
- char *ps = s;
- int n = 0;
-
- while (1)
- {
- c = (char) getchar();
- putchar(c);
-
- if (q && !n && (toupper(c) == 'Q'))
- break;
-
- if ((c == '\n') || (c == '\r'))
- break;
-
- if (isprint(c))
- {
- *s++ = toupper(c);
- n++;
- }
- }
- *s = '\0';
- if (mon_handle)
- write(mon_handle,ps,strlen(ps));
- }
-
- struct termios ttysave;
-
- setmodes()
- {
- struct termios ttysnew;
-
- ioctl(0, TCGETS, &ttysave);
- ttysnew = ttysave;
- ttysnew.c_cflag &= ~CSIZE;
- ttysnew.c_cflag |= CS8;
- ttysnew.c_cflag &= ~PARENB;
- ttysnew.c_oflag &= ~OLCUC;
-
- ttysnew.c_iflag = (IXANY | IGNPAR | IXON | ISTRIP);
- ttysnew.c_lflag = ISIG;
- ttysnew.c_cc[VINTR] = 0x0b; /* Control K */
- ttysnew.c_cc[VSUSP] = NULL;
- ttysnew.c_cc[4] =1;
- ttysnew.c_cc[5] =5;
-
- /* set new paramters */
- ioctl(0, TCSETSF, &ttysnew);
- }
-
-
- /*
- ** restore original tty modes
- */
- restoremodes()
- {
- ioctl(0, TCSETSF, &ttysave);
- }
-
- monitor()
- {
- FILE *fp;
- char sbuf[256];
- char montty[32];
- struct termios newtty;
-
- struct stat st;
-
- mon_handle = 0;
-
- sprintf(sbuf,"/tmp/montty");
- if (stat(sbuf,&st))
- return(0);
-
- if ((fp = fopen(sbuf,"r")) == NULL)
- return(0);
-
- fscanf(fp,"%s",montty);
- fclose(fp);
-
- if (!strlen(montty))
- return(0);
-
- if ((mon_handle = open(montty,
- O_WRONLY|O_NDELAY|O_NOCTTY)) == -1)
- return(0);
- else
- {
- ioctl(mon_handle, TCGETS, &newtty);
- newtty.c_lflag = ISIG;
- ioctl(mon_handle, TCSETSF, &newtty);
- tcflush(mon_handle,TCIOFLUSH);
- }
- return(mon_handle);
- }
-
- mprintf(fmt,s1,s2,s3,s4,s5,s6,s7,s8)
- char *fmt;
- char *s1;
- char *s2;
- char *s3;
- char *s4;
- char *s5;
- char *s6;
- char *s7;
- char *s8;
- {
- char pbuf[1024];
-
- printf(fmt,s1,s2,s3,s4,s5,s6,s7,s8);
- if (mon_handle)
- {
- sprintf(pbuf,fmt,s1,s2,s3,s4,s5,s6,s7,s8);
- write(mon_handle,pbuf,strlen(pbuf));
- }
- }
-